var check;

function setVariables() {
    tablewidth = 280;  // logo width, in pixels
    tableheight = 20;  // logo height, in pixels

    horz = ".pixelLeft";
    vert = ".pixelTop";
    docStyle = "";
    styleDoc = ".style";
    innerW = "document.body.clientWidth";
    innerH = "document.body.clientHeight";
    offsetX = "document.body.scrollLeft";
    offsetY = "document.body.scrollTop";

}//
function checkLocation() {
    if (check) {
        objectXY = "softkeyboard";
        var availableX = eval(innerW);
        var availableY = eval(innerH);
        var currentX = eval(offsetX);
        var currentY = eval(offsetY);
        x = availableX - tablewidth + currentX;
//y=availableY-tableheight+currentY;
        y = currentY;
        evalMove();
    }
    setTimeout("checkLocation()", 0);
}

function evalMove() {
//eval(docStyle + objectXY + styleDoc + horz + "=" + x);
    eval(docStyle + objectXY + styleDoc + vert + "=" + y);
}
self.onError = null;
currentX = currentY = 0;
whichIt = null;
lastScrollX = 0;
lastScrollY = 0;

function heartBeat() {
    diffY = document.body.scrollTop;
    diffX = document.body.scrollLeft;

    if (diffY != lastScrollY) {
        percent = .1 * (diffY - lastScrollY);
        if (percent > 0) percent = Math.ceil(percent);
        else percent = Math.floor(percent);
        document.all.softkeyboard.style.pixelTop += percent;
        lastScrollY = lastScrollY + percent;
    }
    if (diffX != lastScrollX) {
        percent = .1 * (diffX - lastScrollX);
        if (percent > 0) percent = Math.ceil(percent);
        else percent = Math.floor(percent);
        document.all.softkeyboard.style.pixelLeft += percent;
        lastScrollX = lastScrollX + percent;
    }
}
function checkFocus(x, y) {
    stalkerx = document.softkeyboard.pageX;
    stalkery = document.softkeyboard.pageY;
    stalkerwidth = document.softkeyboard.clip.width;
    stalkerheight = document.softkeyboard.clip.height;
    if ((x > stalkerx && x < (stalkerx + stalkerwidth)) && (y > stalkery && y < (stalkery + stalkerheight))) return true;
    else return false;
}
function grabIt(e) {
    check = false;

    whichIt = event.srcElement;
    while (whichIt.id.indexOf("softkeyboard") == -1) {
        whichIt = whichIt.parentElement;
        if (whichIt == null) {
            return true;
        }
    }
    whichIt.style.pixelLeft = whichIt.offsetLeft;
    whichIt.style.pixelTop = whichIt.offsetTop;
    currentX = (event.clientX + document.body.scrollLeft);
    currentY = (event.clientY + document.body.scrollTop);
    return true;
}

function moveIt(e) {
    if (whichIt == null) {
        return false;
    }
    newX = (event.clientX + document.body.scrollLeft);
    newY = (event.clientY + document.body.scrollTop);
    distanceX = (newX - currentX);
    distanceY = (newY - currentY);
    currentX = newX;
    currentY = newY;
    whichIt.style.pixelLeft += distanceX;
    whichIt.style.pixelTop += distanceY;
    if (whichIt.style.pixelTop < document.body.scrollTop)
        whichIt.style.pixelTop = document.body.scrollTop;
    if (whichIt.style.pixelLeft < document.body.scrollLeft)
        whichIt.style.pixelLeft = document.body.scrollLeft;
    if (whichIt.style.pixelLeft > document.body.offsetWidth - document.body.scrollLeft - whichIt.style.pixelWidth - 20)
        whichIt.style.pixelLeft = document.body.offsetWidth - whichIt.style.pixelWidth - 20;
    if (whichIt.style.pixelTop > document.body.offsetHeight + document.body.scrollTop - whichIt.style.pixelHeight - 5)
        whichIt.style.pixelTop = document.body.offsetHeight + document.body.scrollTop - whichIt.style.pixelHeight - 5;
    event.returnValue = false;
    return false;
}
function dropIt() {
    whichIt = null;

    document.onmousedown = grabIt;
    document.onmousemove = moveIt;
    document.onmouseup = dropIt;
}


//
//给输入的密码框添加新
function addValue(newValue) {
    document.getElementById("callOutPhoneNum").value += newValue;
}

function callOut(outNum) {
    let number = $('#callOutPhoneNum').val();
    if (number.length === 0) {
        top.softphone.showErrorInfo('提示', '请输入外拨号码!', true); return;
    }
    outBoundClick(outNum + number);
    closekeyboard();
}

function clearall() {
    document.getElementById("callOutPhoneNum").value = "";
}
//实现BackSpace键的功能
function setpassvalue() {
    var longnum = document.getElementById("callOutPhoneNum").value.length;
    var num
    num = document.getElementById("callOutPhoneNum").value.substr(0, longnum - 1);
    document.getElementById("callOutPhoneNum").value = num;

}

//关闭软键盘
function closekeyboard() {
    document.getElementById("softkeyboard").style.display = "none"
}
function showkey() {
    showkeyboard();
}
//显示软键盘
function showkeyboard() {
    document.getElementById("softkeyboard").style.display = "block";
}
